import java.util.Scanner;

public class Player {
    /*
     * 封装了
     * */
    private int[] guessS = {18, 12, 8, 5, 3, 2};
    /**
     * 玩家的姓名
     */
    private String name;
    /**
     * 玩家猜测的数量
     */
    private int guessCount;
    /**
     * 分数
     */
    private int score;

    /**
     * 本轮最后一个数字
     */
    private int endNumber;

    public Player(String name, int guessCount) {
        this.name = name;
        this.guessCount = guessCount;
    }

    public Player(String name, int guessCount, int score) {
        this.name = name;
        this.guessCount = guessCount;
        this.score = score;
    }

    public Player() {
    }

    public int[] getGuessS() {
        return guessS;
    }

    public void setGuessS(int[] guessS) {
        this.guessS = guessS;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getEndNumber() {
        return endNumber;
    }

    public void setEndNumber(int endNumber) {
        this.endNumber = endNumber;
    }

    public int getGuessCount() {
        return guessCount;
    }

    public void setGuessCount(int guessCount) {
        this.guessCount = guessCount;
    }

    public void addGuessCount() {
        guessCount++;
    }

    /*
     * 玩家猜数
     * */
    public NumberGenerator guessNumber(int min, int max) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("猜一个整数在" + min + "-" + max + "之间");
        if (scanner.hasNextInt()) {
            int number = scanner.nextInt();
            //endNumber = number;
            NumberGenerator numberGenerator = new NumberGenerator(number, false);
            if (number == 999) {
                numberGenerator.setFlag(true);
                guessCount++;
                return numberGenerator;
            }

            if (number >= min && number <= max) {
                guessCount++;
                return numberGenerator;
            }
            if (number >= 1 && number <= 100) {
                guessCount++;
                numberGenerator.setFlag(true);
                return numberGenerator;
            }
            if (number < 1 || number > 100) {
                System.out.println("警告，请输入" + min + "-" + max + "之间整数");
                return guessNumber(min, max);
            }


        } else {
            System.out.println("输入的类型不准确");
            /*
             * 递归
             * */
            return guessNumber(min, max);
        }
        return new NumberGenerator(-1, false);
    }

    //public static void main(String[] args) {
    //    guessNumber(5, 100);
    //}

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                ", guessCount=" + guessCount +
                ", score=" + score +
                ", endNumber=" + endNumber +
                '}';
    }

    /**
     * 增加玩家的分数
     */
    public void addscore(int AllguessCounnt) {
        if (AllguessCounnt <= 6 && AllguessCounnt > 0) {
            setScore(guessS[AllguessCounnt - 1] + getScore());
            System.out.println(name + "加" + guessS[AllguessCounnt - 1] + "分");
        } else {
            setScore(0 + getScore());
            System.out.println(name + "加" + 0 + "分");
        }
    }

}


